import {action, observable, runInAction} from "mobx";
import {BaseResInterface, BaseResInterfaceWithData, sendGetRequest, sendPostRequest, uploadFile} from "../../../net";
import UserStoreInstance, {validPhoneResInterface} from "./index";
import {UserRealInfoInterface} from "../../../net/instance/CommenModelInstance";


interface Verified {
    verificationCode: number,
    id: number
}

export class VerifiedStore {
    @observable verificationCode: string;

    @action.bound
    async validUserPhone(phone: string) {
        const {data, code} = await sendPostRequest<validPhoneResInterface>("user/validPhone", {
            phone
        });

        data && runInAction(() => {
            this.verificationCode = data.verificationCode + "";
        });
        return code;

    }

    async insertUserRealInfo(realInfo: UserRealInfoInterface) {
        const {data} = await sendPostRequest<BaseResInterfaceWithData<Verified>>("user/insertUserRealInfo", {
            realInfo,
            userId:UserStoreInstance.user.id
        });
        return data;
    }


}

const VerifiedStoreInstance = new VerifiedStore();
export default VerifiedStoreInstance